import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    user:
      window.localStorage.getItem("user") == null
        ? null
        : JSON.parse(window.localStorage.getItem("user")),
    menuList:
      window.localStorage.getItem("menuList") == []
        ? []
        : JSON.parse(window.localStorage.getItem("menuList")),
  },
  mutations: {
    login(state, user) {
      state.user = user;
      window.localStorage.setItem("user", JSON.stringify(user));
    },
    logout(state) {
      state.user = null;
      window.localStorage.removeItem("user");
    },
    getMenuList(state, menuList) {
      state.menuList = menuList;
      window.localStorage.setItem("menuList", JSON.stringify(menuList));
    },
  },
  actions: {},
  modules: {},
});
